package controllers;

import java.util.Date;

import models.Event;

public class Tools {

	/**
	 * splits a string of the format yyyy-mm-dd into year month and day
	 * @param dateString
	 * @return An int[3] with year, month and day
	 */
	public static int[] splitDate(String dateString) {
		int[] date = new int[3];
		String[] split = new String[3];
		
		if (dateString.length() == 10) {
			split = dateString.split("-");
		
			for(int i=0; i<3; i++) {
				date[i] = Integer.parseInt(split[i]);
			}
		}
		
		return date;
	}

	/**
	 * Make sure the offer takes place during the event or at least for the day before.
	 * 
	 * @param startDate
	 * @param endDate
	 * @param event
	 * @return
	 */
	public static boolean isOfferWithinEventTimeRange(Date startDate, Date endDate, Event event){
		if (endDate.before(event.startDate) || startDate.after(event.endDate))
			return false;
		return true;
	}

	/**
	 * 
	 * @param start
	 * @param end
	 * @return
	 */
	public static boolean isStartDateBeforeEndDate(Date start, Date end){
		if (start == null || end == null )
			return false;
		else if(start.after(end))
			return false;
		return true;
		
	}
}
